package com.bo.wei.chen.mybatis.filter;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import lombok.extern.slf4j.Slf4j;

/**
 * TODO
 *
 * @author chenwb25485
 * @version V2.1
 * @since 2020/9/1 16:40
 */
@Slf4j
public class LogInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
	throws Exception {
		long startTime = System.currentTimeMillis();
		System.out.println("***preHandle***" + "startTime" + startTime);
		log.info("***preHandle***" + "startTime" + startTime);
		return super.preHandle(request, response, handler);
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
		ModelAndView modelAndView) throws Exception {
		long endTime = System.currentTimeMillis();
		System.out.println("***postHandle***" + "startTime" + endTime);
		log.info("***postHandle***" + "startTime" + endTime);
		super.postHandle(request, response, handler, modelAndView);
	}

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
	throws Exception {
		long endTime = System.currentTimeMillis();
		System.out.println("***afterCompletion***" + "startTime" + endTime);
		log.info("***afterCompletion***" + "startTime" + endTime);
		super.afterCompletion(request, response, handler, ex);
	}
}
